package com.cms.rxjava

import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.android.baselibrary.base.BaseDBActivity
import com.cms.rxjava.databinding.ActivityRxBaseBinding
import com.cms.rxjava.router.RxRouter


/**
 * rxbase
 */
@Route(path = RxRouter.RxJava_Base_Fragment)
class RxBaseActivity : BaseDBActivity<ActivityRxBaseBinding>(R.layout.activity_rx_base) {
    @JvmField
    @Autowired(name = RxRouter.RxJava_Parame)
    var fragmentPath: String = ""
    override fun initView() {
         if (fragmentPath.isNullOrEmpty()){
             return
         }

        var targetFragment = supportFragmentManager.findFragmentByTag(fragmentPath)
        if (targetFragment == null){
            targetFragment = ARouter.getInstance().build(fragmentPath).navigation() as Fragment?
            if (targetFragment == null){
                finish()
                return
            }
            supportFragmentManager.beginTransaction().replace(R.id.fragment,targetFragment).commitAllowingStateLoss()
        }

    }

    override fun initVMData() {
    }
}